<template>
  <layout>
    <template slot="other">
      <a-button type="primary" @click="handlerExport">导出错误信息到Execl</a-button>
    </template>
    <!-- 产品列表 -->
    <a-table
      :dataSource="tableData"
      :columns="calcColumns"
      :rowKey="record => record.content"
      :customRow="customTableRow"
      :pagination="false"
      size='small'
      :scroll="{
        x: '100%',
        y: 520
      }"
      bordered
    >
    </a-table>

    <a-pagination
      slot="paging"
      :pageSizeOptions="pageSizes"
      :total="total"
      :show-total="showTotal"
      showSizeChanger
      :pageSize="pageSize"
      v-model="currentPage"
      @showSizeChange="changePageSize"
      @change="changePage"
    >
    </a-pagination>
  </layout>
</template>

<script lang="ts">
import { Mixins, Component, Watch, Vue, Prop } from 'vue-property-decorator'
import EventsMixin from '@/mixin/events'
import { TableMixin, AuthMixin } from '@/mixin'

import { TableLayout } from '@/layouts'
import CustomForm from '@/components/src/Form'
import { exportDataHandler } from '@/utils/execl'

@Component({
  components: {
    Layout: TableLayout,
    CustomForm,
  }
})
export default class AdminList extends Mixins(
  EventsMixin,
  TableMixin,
  AuthMixin
) {
  @Prop({
    type: Array
  })
  public messages!: Array<string>

  public commonParams = {
    s_a_id: ''
  }

  // 产品列表搜索条件
  public tableSearch = {
  }

  // 自定义mode
  public customMode = 'search'

  get calcColumns () {
    return [
      {
        title: '详细错误描述',
        dataIndex: 'content',
        key: 'content',
        width: 180
      }
    ]
  }

  // 产品列表表格信息
  public columns: ITable.IColumn[] = []

  public tableApi = {
    // list: payServices.getBankReceipts,
    // add: famerServices.updateMemberGrain,
    // edit: payServices.editBankReceipt,
    // del: payServices.delBank,
    // imageUpload: 'uploadStoreImage',
    // imageRemove: 'delStoreImage'
  }

  @Watch('messages', { immediate: true })
  public handlerChangeExecl() {
    this.total = this.messages.length
    
    this.getData()
  }

  public mounted() {
    // this.tableData = this.execlData || []
  }

  public async getData() {
    // const res = await this.getTableList()
    this.tableData = this.messages.slice((this.currentPage - 1) * this.pageSize, this.currentPage * this.pageSize)
    // this.tableData = []
  }

  public handlerExport() {
    const fields = {
      content: '详细错误描述'
    }
    exportDataHandler(this.messages, fields, '详细错误描述表.xlsx')
  }
}
</script>

<style scoped lang="less">
.action-button {
  margin: 0px 10px 0px 10px;
}
.upload-button {
  position: relative;
  input {
    position: absolute;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    z-index: 2;
    opacity: 0;
  }
}
.form-item-class {
  margin-bottom: 0px;
}
.img-box {
  width: 100px;
  height: 100px;
  margin: 10px;
}
.item-blue {
  color: #1989fa;
}
</style>
